<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a>首页管理</a>
    <a><cite>logo</cite></a>
  </div>
</div>
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-card-body">
          <table class="layui-hide" id="table-logo" lay-filter="table-logo"></table>
          <script type="text/html" id="table-useradmin-webuser">
                      <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                  </script>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  layui.use(['carousel', 'form', 'admin', 'element', 'useradmin', 'table', 'laydate', 'layedit'], function () {
    var carousel = layui.carousel,
      $ = layui.$,
      setter = layui.setter,
      view = layui.view,
      table = layui.table,
      form = layui.form,
      elem = layui.element,
      admin = layui.admin,
      laydate = layui.laydate,
      layedit = layui.layedit;
    table.render({
      elem: "#table-logo", //表id
      url: setter.request.baseUrl + "/ours/frontend/info",
      method: "get",
      headers: {
        token: layui.data("layuiAdmin").token
      },
      response: {
        statusName: "code",
        statusCode: 0,
        msgName: "msg",
        countName: "count",
        dataName: "ours",
      },
      cols: [
        [{
          align: 'center',
          field: "logoId",
          width: "4%",
          sort: true
        }, {
          align: 'center',
          field: "pageTop",
          width: "8%",
          title: "页面顶部"
        }, {
          field: "topLogo",
          title: "顶部logo"
        }, {
          field: "bottomLogo",
          title: "底部logo"
        }, {
          field: "name",
          width: "17%",
          align: 'center',
          title: "公司名称"
        }, {
          field: "recordNo",
          width: "12%",
          align: 'center',
          title: "备案号"
        }, {
          field: "address",
          title: "公司地址"
        }, {
          field: "englishAddr",
          title: "英文地址"
        }, {
          field: "phone",
          align: 'center',
          width: "8%",
          title: "电话"
        }, {
          field: "email",
          width: "12%",
          align: 'center',
          title: "邮箱地址"
        }, {
          field: "codeImg",
          title: "二维码"
        }, {
          fixed: "right",
          title: "操作",
          align: 'center',
          toolbar: "#table-useradmin-webuser"
        },],
      ],
      page: false,
    });

    $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

    //监听右侧的编辑模块
    table.on("tool(table-logo)", function (obj) {
      var data = obj.data;
      console.log(data)
      if (obj.event === "edit") {
        admin.popup({
          title: "更新logo",
          area: ["800px", "800px"],
          success: function (layero, index) {
            view(this.id)
              .render("countpoint/table", data)
              .done(function () {
                let _data = data;
                form.render(null, "layuiadmin-form-admin");
                //富文本
                var aa = layedit.build('demo');
                console.log(data)
                layedit.setContent(aa, data.introduct, false)
                //监听提交
                form.on('submit(LAY-user-front-submit)', function (data) {
                  var field = data.field; //获取提交的字段
                  var aahtml = layedit.getContent(aa);
                  field.introduct = aahtml
                  field.isHot = data.field.isHot == 'on' ? '1' : 0
                  console.log(data.field)
                  //提交 Ajax 成功后，关闭当前弹层并重载表格
                  adminAdd(field);
                  layui.table.reload("table-instance");
                  layer.close(index); //执行关闭 
                });
              });
          },
        });
      }

    })
  })
</script>